import json
def save_to_file(data):
    """Save data to the data/items.json file"""
    with open("data/items.json",'w') as file:
        json.dump({"magic bread":data},file,indent=4)
    return None

def load_from_file():
    """Load data from data/items.json"""
    try:
        with open("data/items.json",'r') as file:
            loaded_dict=json.load(file)
            return loaded_dict.get("magic bread",{})
    except FileNotFoundError:
        return {}

if __name__=="__main__":
    test_data={
        "magic bread":[
            {
                "ID":"123abc",
                "type":"Chocolate Lava Croissant",
                "name":"Crispy",
                "character":"open and outgoing",
                "property":"fire magic"
            },
            {
                "ID":"456def",
                "type":"Iceberg Cream Cheese Bread",
                "name":"Creamout",
                "character":"aloof yet tender",
                "property":"ice magic"
            }
        ]
    }

    save_to_file(test_data)
    print("Data has been saved to data/items.json.")

    loaded_data=load_from_file()
    print("Loaded data:")
    print(loaded_data)
